package com.mtnz.njk.Controller;

import com.mtnz.njk.Service.ProductManagerService;
import com.mtnz.njk.entity.*;
import com.mtnz.njk.model.ProductManagerListModel;
import com.mtnz.njk.model.UpdateActiveProductModel;
import com.mtnz.njk.result.ResponseMessage;
import com.mtnz.njk.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 商品管理控制层
 * @Author: FBL
 * @CreateDate: 2019\8\12 0012 19:43
 * @Version: 1.0
 */
@RestController
@RequestMapping("/product")
@CrossOrigin
public class ProductManagerController {

    @Autowired
    ProductManagerService productManagerService;

    /**
     * 查询商品列表
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/listProduct")
    public ResponseResult listProduct(String key, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return productManagerService.listProduct(key, pageNum, pageSize);
    }

    /**
     * 查询商品帖子
     *
     * @param key
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listProductResearch")
    public ResponseResult listProductResearch(String key, String productId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        if (productId == null || ("").equals(productId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.listProductResearch(key, pageNum, pageSize, productId);
    }

    /**
     * 修改商品信息
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/updateProduct")
    public ResponseResult updateProduct(@RequestBody ProductManagerListModel productManagerListModel) throws Exception {
        if (productManagerListModel == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateProduct(productManagerListModel);
    }

    /**
     * 新增商品信息
     *
     * @param productManagerListModel
     * @return
     * @throws Exception
     */
    @PostMapping("/insertProduct")
    public ResponseResult insertProduct(@RequestBody ProductManagerListModel productManagerListModel) throws Exception {
        if (productManagerListModel == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertProduct(productManagerListModel);
    }

    /**
     * 商品滚动图的添加
     *
     * @param productId
     * @param productImg
     * @return
     * @throws Exception
     */
    @PostMapping("/insertProductImg")
    public ResponseResult insertProductImg(String productId, String productImg) throws Exception {
        if (productId == null || ("").equals(productId) || productImg == null || ("").equals(productImg))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertProductImg(productId, productImg);
    }

    /**
     * 删除商品滚动图
     *
     * @param productImgId
     * @return
     * @throws Exception
     */
    @PostMapping("/delProductImg")
    public ResponseResult delProductImg(String productImgId) throws Exception {
        if (productImgId == null || ("").equals(productImgId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delProductImg(productImgId);
    }

    /**
     * 新增产品规格
     *
     * @param productRemarkEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertProductRemark")
    public ResponseResult insertProductRemark(@RequestBody ProductRemarkEntity productRemarkEntity) throws Exception {
        if (productRemarkEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertProductRemark(productRemarkEntity);
    }

    /**
     * 编辑产品规格
     *
     * @param productRemarkEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateProductRemark")
    public ResponseResult updateProductRemark(@RequestBody ProductRemarkEntity productRemarkEntity) throws Exception {
        if (productRemarkEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateProductRemark(productRemarkEntity);
    }

    /**
     * 删除产品规格
     *
     * @param remarkId
     * @return
     * @throws Exception
     */
    @PostMapping("/delProductRemark")
    public ResponseResult delProductRemark(String remarkId) throws Exception {
        if (remarkId == null || ("").equals(remarkId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delProductRemark(remarkId);
    }

    /**
     * 新增商品一级类型
     *
     * @param productTypeEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertProductType")
    public ResponseResult insertProductType(@RequestBody ProductTypeEntity productTypeEntity) throws Exception {
        if (productTypeEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertProductType(productTypeEntity);
    }

    /**
     * 删除商品一级类型
     *
     * @param productTypeId
     * @return
     * @throws Exception
     */
    @PostMapping("/delProductType")
    public ResponseResult delProductType(String productTypeId) throws Exception {
        if (productTypeId == null || ("").equals(productTypeId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delProductType(productTypeId);
    }

    /**
     * 编辑商品一级类型
     *
     * @param productTypeEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateProductType")
    public ResponseResult updateProductType(@RequestBody ProductTypeEntity productTypeEntity) throws Exception {
        if (productTypeEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateProductType(productTypeEntity);
    }

    /**
     * 新增二级类型
     *
     * @param productDetailType
     * @return
     * @throws Exception
     */
    @PostMapping("/insertProductDetailType")
    public ResponseResult insertProductDetailType(@RequestBody ProductDetailTypeEntity productDetailType) throws Exception {
        if (productDetailType == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertProductDetailType(productDetailType);
    }

    /**
     * 删除二级类型
     *
     * @param productDetailId
     * @return
     * @throws Exception
     */
    @PostMapping("/delProductDetailType")
    public ResponseResult delProductDetailType(String productDetailId) throws Exception {
        if (productDetailId == null || ("").equals(productDetailId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delProductDetailType(productDetailId);
    }

    /**
     * 编辑二级类型
     *
     * @param productDetailType
     * @return
     * @throws Exception
     */
    @PostMapping("/updateProductDetailType")
    public ResponseResult updateProductDetailType(@RequestBody ProductDetailTypeEntity productDetailType) throws Exception {
        if (productDetailType == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateProductDetailType(productDetailType);
    }

    /**
     * 展示活动类型列表
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/ListProductActive")
    public ResponseResult ListProductActive() throws Exception {
        return productManagerService.ListProductActive();
    }

    /**
     * 新增活动
     *
     * @param productActiveThresholdEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertActive")
    public ResponseResult insertActive(@RequestBody ProductActiveThresholdEntity productActiveThresholdEntity) throws Exception {
        if (productActiveThresholdEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertActive(productActiveThresholdEntity);
    }

    /**
     * 编辑活动类型
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/updateProductActive")
    public ResponseResult updateProductActive(@RequestBody ProductActiveThresholdEntity productActiveThresholdEntity) throws Exception {
        if (productActiveThresholdEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateProductActive(productActiveThresholdEntity);
    }

    /**
     * 活动商品列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listActiveProduct")
    public ResponseResult listActiveProduct(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return productManagerService.listActiveProduct(pageNum, pageSize);
    }

    /**
     * 删除活动商品
     *
     * @param remarkId
     * @return
     * @throws Exception
     */
    @PostMapping("/delActiveProduct")
    public ResponseResult delActiveProduct(String remarkId) throws Exception {
        if (remarkId == null || ("").equals(remarkId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delActiveProduct(remarkId);
    }

    /**
     * 编辑活动商品
     *
     * @param updateActiveProductModel
     * @return
     * @throws Exception
     */
    @PostMapping("/updateActiveProduct")
    public ResponseResult updateActiveProduct(@RequestBody UpdateActiveProductModel updateActiveProductModel) throws Exception {
        if (updateActiveProductModel == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateActiveProduct(updateActiveProductModel);
    }

    /**
     * 新增活动商品
     *
     * @param updateActiveProductModel
     * @return
     * @throws Exception
     */
    @PostMapping("/insertActiveProduct")
    public ResponseResult insertActiveProduct(@RequestBody UpdateActiveProductModel updateActiveProductModel) throws Exception {
        if (updateActiveProductModel == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertActiveProduct(updateActiveProductModel);
    }

    /**
     * 活动赠品列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listActiveGive")
    public ResponseResult listActiveGive(String key, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return productManagerService.listActiveGive(key, pageNum, pageSize);
    }

    /**
     * 新增赠品
     *
     * @param productActiveGiveEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertActiveGive")
    public ResponseResult insertActiveGive(@RequestBody ProductActiveGiveEntity productActiveGiveEntity) throws Exception {
        if (productActiveGiveEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertActiveGive(productActiveGiveEntity);
    }

    /**
     * 删除活动赠品
     *
     * @param activeGiveId
     * @return
     * @throws Exception
     */
    @PostMapping("/delActiveGive")
    public ResponseResult delActiveGive(String activeGiveId) throws Exception {
        if (activeGiveId == null || ("").equals(activeGiveId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delActiveGive(activeGiveId);
    }

    /**
     * 编辑活动赠品
     *
     * @param productActiveGiveEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateActiveGive")
    public ResponseResult updateActiveGive(@RequestBody ProductActiveGiveEntity productActiveGiveEntity) throws Exception {
        if (productActiveGiveEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateActiveGive(productActiveGiveEntity);
    }

    /**
     * 积分商品列表
     *
     * @param key
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @PostMapping("/listIntegralProduct")
    public ResponseResult listIntegralProduct(Integer integralTypeId, String key, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        return productManagerService.listIntegralProduct(integralTypeId, key, pageNum, pageSize);
    }

    /**
     * 新增积分商品
     *
     * @param integralEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertIntegralProduct")
    public ResponseResult insertIntegralProduct(@RequestBody IntegralEntity integralEntity) throws Exception {
        if (integralEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertIntegralProduct(integralEntity);
    }

    /**
     * 编辑积分商品
     *
     * @param integralEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateIntegralProduct")
    public ResponseResult updateIntegralProduct(@RequestBody IntegralEntity integralEntity) throws Exception {
        if (integralEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateIntegralProduct(integralEntity);
    }

    /**
     * 删除积分商品
     *
     * @param integralId
     * @return
     * @throws Exception
     */
    @PostMapping("/delIntegralProduct")
    public ResponseResult delIntegralProduct(String integralId) throws Exception {
        if (integralId == null || ("").equals(integralId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.delIntegralProduct(integralId);
    }

    /**
     * 积分商品分类编辑
     *
     * @param integralTypeEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/updateIntegralType")
    public ResponseResult updateIntegralType(@RequestBody IntegralTypeEntity integralTypeEntity) throws Exception {
        if (integralTypeEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.updateIntegralType(integralTypeEntity);
    }

    /**
     * 积分商品分类新增
     *
     * @param integralTypeEntity
     * @return
     * @throws Exception
     */
    @PostMapping("/insertIntegralType")
    public ResponseResult insertIntegralType(@RequestBody IntegralTypeEntity integralTypeEntity) throws Exception {
        if (integralTypeEntity == null)
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.insertIntegralType(integralTypeEntity);
    }


    /**
     * 运营数据
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    @PostMapping("/productStatistics")
    public ResponseResult productStatistics(String startTime, String endTime, String status) throws Exception {
        return productManagerService.productStatistics(startTime, endTime, status);
    }

    /**
     * 商品页或积分商品分享次数统计
     *
     * @param startTime
     * @param endTime
     * @param status   0 时，1 天，2 月
     * @return
     * @throws Exception
     */
    @PostMapping("/productShareStatistics")
    public ResponseResult productShareStatistics(String startTime, String endTime, Integer status, Integer communityType,String communityId) throws Exception {
        if (status == null || communityType == null || communityId == null || ("").equals(communityId))
            return new ResponseResult(ResponseMessage.NULL_REQUEST);
        return productManagerService.productShareStatistics(startTime, endTime, status, communityType,communityId);
    }

}
